package com.ruoyi.web.controller.classSeat;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.domain.ClassUser;
import com.ruoyi.web.service.IClassUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 *  Controller
 *

 * @date 2022-03-15
 */
@RestController
@RequestMapping("/system/userClass")
public class ClassUserClassController extends BaseController
{
    @Autowired
    private IClassUserService classUserService;

    /**
     * 查询 列表
     */
    @PreAuthorize("@ss.hasPermi('system:userClass:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClassUser classUser)
    {
        startPage();
        List<ClassUser> list = classUserService.selectClassUserList(classUser);
        return getDataTable(list);
    }

    /**
     * 导出 列表
     */
    @PreAuthorize("@ss.hasPermi('system:userClass:export')")
    @Log(title = " ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClassUser classUser)
    {
        List<ClassUser> list = classUserService.selectClassUserList(classUser);
        ExcelUtil<ClassUser> util = new ExcelUtil<ClassUser>(ClassUser.class);
        util.exportExcel(response, list, " 数据");
    }

    /**
     * 获取 详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:userClass:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(classUserService.selectClassUserById(id));
    }

    /**
     * 新增
     */
    @PreAuthorize("@ss.hasPermi('system:userClass:add')")
    @Log(title = " ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClassUser classUser)
    {
        return toAjax(classUserService.insertClassUser(classUser));
    }



    @PreAuthorize("@ss.hasPermi('system:userClass:order')")
    @Log(title = " ", businessType = BusinessType.INSERT)
    @PostMapping("/order")

        public AjaxResult orderseat(@RequestBody ClassUser classUser)
    {
        System.out.println("213");
        classUserService.orderClass(classUser);
        return AjaxResult.success();
    }
    @PreAuthorize("@ss.hasPermi('system:userClass:cancel')")
    @Log(title = " ", businessType = BusinessType.INSERT)
    @PostMapping("/cancel")

    public AjaxResult cancelseat(@RequestBody ClassUser classUser)
    {
        System.out.println("213");
        classUserService.cancalClass(classUser);
        return AjaxResult.success();
    }
    /**
     * 修改
     */
    @PreAuthorize("@ss.hasPermi('system:userClass:edit')")
    @Log(title = " ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClassUser classUser)
    {
        return toAjax(classUserService.updateClassUser(classUser));
    }

    /**
     * 删除
     */
    @PreAuthorize("@ss.hasPermi('system:userClass:remove')")
    @Log(title = " ", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(classUserService.deleteClassUserByIds(ids));
    }
}
